#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc,char **argv)
{
  int shm_id;
  struct stat buf;
  char *ptr;
  if (argc !=2)
  {
    printf("usage:shm_open <pathname>\n");
    exit(1);
  }
  shm_id = shm_open(argv[1],O_RDWR|O_CREAT,0644);
  fstat(shm_id,&buf);
  printf("before ....\n");
  printf("uid_t:%d \n",buf.st_uid);
  printf("git_t:%d \n",buf.st_gid);
  printf("size :%d \n",buf.st_size);
  ftruncate(shm_id,100);
  fstat(shm_id,&buf);
  printf("after ....\n");
  printf("uid_t:%d \n",buf.st_uid);
  printf("git_t:%d \n",buf.st_gid);
  printf("size :%d \n",buf.st_size);
  ptr = mmap(NULL,buf.st_size,PROT_READ|PROT_WRITE,MAP_SHARED,shm_id,0);
  strcpy(ptr,"hello linux");
  printf("%s .\n",ptr);
  shm_unlink(argv[1]);
  munmap(ptr,buf.st_size);
  return 0;
  
}
